package com.boco.blch.analysiser.compliance.HW.manager;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.util.StringUtils;

import com.boco.blch.analysiser.compliance.ComplianceResolved;
import com.boco.blch.analysiser.util.XmlUtil;

/**
 * @author 黄戈
 * HBase服务连接数限制安全基线要求项
 *
 */

public class BOCO_Hbase_VisitCtl_SerLinkNum implements ComplianceResolved {
	
	private final static String HbaseP1 ="hbase.sessioncontrol.maxconnectionsperuser";
	private final static String HbaseP2="hbase.sessioncontrol.maxconnections";

	@Override
	public int realEchoResolved(String echoResult) {
		if(!echoResult.equals("")&&echoResult!= null&&(!echoResult.contains(NoPermission1)&&!echoResult.contains(NoPermission2)&&!echoResult.contains(NoPermission3))){
			String ManagerResult=echoResult;//.substring(echoResult.indexOf("manager-start")+"manager-start".length(),echoResult.indexOf("manager-end")).trim();
			if(!ManagerResult.contains(NotFindFile)&&!ManagerResult.contains("boco-HBase-result:error")){
			String HbaseResult1=XmlUtil.getValueByName(ManagerResult,HbaseP1);
			//System.out.println(HbaseResult1);
			String HbaseResult2=XmlUtil.getValueByName(ManagerResult,HbaseP2);
			//System.out.println(HbaseResult2);
			if((HbaseResult1!=null&&!StringUtils.isEmpty(HbaseResult1)&&!HbaseResult1.equals("null")&&isNumeric(HbaseResult1)&&Integer.valueOf(HbaseResult1)<=65535)&&(!HbaseResult2.equals(null)&&!StringUtils.isEmpty(HbaseResult2)&&isNumeric(HbaseResult2)&&Integer.valueOf(HbaseResult2)<=65535)){
				return SUCCESS;
			}else{
				return FAILED;
			}
		  }else{
			  return FAILED;
		  }
		}else{
			return FAILED;
		}
		
	}
	
	public boolean isNumeric(String str){
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if( !isNum.matches() ){
            return false;
        }
        return true;
 }
	

	/*
*/

}
